import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart';
import 'package:kunlun_gas/app_files.dart';

import 'action.dart';
import 'state.dart';

Widget buildView(
    OrderHistoryViewState state, Dispatch dispatch, ViewService viewService) {
  Widget _build(BuildContext context,int index) {
    Map<String, Color> colors = {
      '正常': Color.fromRGBO(108, 153, 250, 1),
      '隐患': Color.fromRGBO(254, 193, 98, 1),
      '维修': Color.fromRGBO(252, 117, 106, 1),
      '自修': Color.fromRGBO(252, 117, 106, 1),
    };

    var item = state.items[index];
    if (item is CheckListItemModel) {
      return Container(
        margin: EdgeInsets.only(left: 15, right: 15, top: 10),
        width: ScreenUtil.screenWidthDp,
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.all(Radius.circular(4)),
        ),
        child: InkWell(
          child: Column(
            children: [
              Container(
                padding: EdgeInsets.all(15),
                child: Column(
                  children: [
                    Row(
                      children: [
                        Text(
                          '客户名称：',
                          style: TextThemeConfig.Font14WithColor99,
                        ),
                        Text(
                          item.userName,
                          style: TextThemeConfig.Font14WithColor22,
                        ),
                      ],
                    ),
                    Padding(
                      padding: EdgeInsets.symmetric(vertical: 8),
                      child: Row(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Text(
                            '客户地址：',
                            style: TextThemeConfig.Font14WithColor99,
                          ),
                          Expanded(
                            child: Text(
                              item.userAddress,
                              maxLines: 1,
                              style: TextThemeConfig.Font14WithColor22,
                              overflow: TextOverflow.ellipsis,
                            ),
                          ),
                        ],
                      ),
                    ),
                    Row(
                      children: [
                        Text(
                          '联系方式：',
                          style: TextThemeConfig.Font14WithColor99,
                        ),
                        Text(
                          item.phone,
                          style: TextThemeConfig.Font14WithColor22,
                        ),
                      ],
                    ),
                    Padding(
                      padding: EdgeInsets.only(top: 8),
                      child: Row(
                        children: [
                          Expanded(
                              child: Row(
                                children: [
                                  Text(
                                    '安检状态：',
                                    style: TextThemeConfig.Font14WithColor99,
                                  ),
                                  Text(
                                    item.checked ? '已检查' : '未检查',
                                    style: TextThemeConfig.Font14WithColor22,
                                  ),
                                ],
                              )),
                          Expanded(
                              child: Row(
                                children: [
                                  Text(
                                    '安全隐患：',
                                    style:
                                    TextThemeConfig.Font14WithColor99,
                                  ),
                                  Text(
                                    item.checkStatusStr,
                                    style: TextStyle(
                                      color: colors[item.checkStatusStr] ??
                                          Color(0xFF222222),
                                      fontSize: 14,
                                      fontWeight: FontWeight.w500,
                                    ),
                                  ),
                                ],
                              ))
                        ],
                      ),
                    ),
                    item.checked
                        ? Padding(
                      padding: EdgeInsets.only(top: 8),
                      child: Row(
                        children: [
                          Text(
                            '安检时间：',
                            style: TextThemeConfig.Font14WithColor99,
                          ),
                          Text(
                            item.checkTime,
                            style: TextThemeConfig.Font14WithColor22,
                          ),
                        ],
                      ),
                    )
                        : Container(),
                  ],
                ),
              ),
            ],
          ),
          onTap: () => CommonUtils.pushRoute(context, RoutePath.orderResultView,
              arguments: {'info': item})

//        onTap: () => CommonUtils.pushRoute(
//          context,
//          RoutePath.orderView,
//          arguments: {'info': item},
//        ),
        ),
      );
    }
    else {
      return Container(
        margin: EdgeInsets.only(left: 15, right: 15, top: 10),
        width: ScreenUtil.screenWidthDp,
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.all(Radius.circular(4)),
        ),
        child: InkWell(
            child: Column(
              children: [
                Container(
                  padding: EdgeInsets.all(15),
                  child: Column(
                    children: [
                      Row(
                        children: [
                          Text(
                            '客户名称：',
                            style: TextThemeConfig.Font14WithColor99,
                          ),
                          Text(
                            CommonUtils.checkNullToString(item['name']),
                            style: TextThemeConfig.Font14WithColor22,
                          ),
                        ],
                      ),
                      Padding(
                        padding: EdgeInsets.symmetric(vertical: 8),
                        child: Row(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Text(
                              '客户地址：',
                              style: TextThemeConfig.Font14WithColor99,
                            ),
                            Expanded(
                              child: Text(
                                CommonUtils.checkNullToString(item['orderInfo']),
                                maxLines: 1,
                                style: TextThemeConfig.Font14WithColor22,
                                overflow: TextOverflow.ellipsis,
                              ),
                            ),
                          ],
                        ),
                      ),
                      Row(
                        children: [
                          Text(
                            '挂表时间：',
                            style: TextThemeConfig.Font14WithColor99,
                          ),
                          Text(
                            CommonUtils.checkNullToString(item['successTime']),
                            style: TextThemeConfig.Font14WithColor22,
                          ),
                        ],
                      ),
                    ],
                  ),
                ),
              ],
            ),
            onTap: () => CommonUtils.pushRoute(context, RoutePath.installHistoryDetailView,
                arguments: {'info': item})

//        onTap: () => CommonUtils.pushRoute(
//          context,
//          RoutePath.orderView,
//          arguments: {'info': item},
//        ),
        ),
      );
    }
   return Container();
  }

  return Scaffold(
    appBar: myAppBar(viewService.context, title: '历史记录'),
    body: state.items == null ? MyLoadingWidget() : ListView.builder(itemBuilder: _build,itemCount: state.items.length,),
  );
}
